using System;
using System.Collections.Generic;
using System.Text;
using DataTools;
using DataTools.PagingUtils;
using ObjectLayer;

namespace CommonAccessLayer
{
	public class user_infoDAO
{
		public static List<user_infoBO> GetAll()
		{
			return CBO.FillCollection<user_infoBO>(DataProvider.getInstance().getAll(TableName.user_info, PagingHelper.CreateOrder(new OrderObject(user_infoTable.user_id, SortOrder.Desc))));
		}
		static object _Clock = new object();
		public static List<user_infoBO> GetAllC()
		{
			List<user_infoBO> list = new List<user_infoBO>();
			if(DataCache.GetCache(CacheName.user_info) == null)
			{
				lock (_Clock)
				{
					if (DataCache.GetCache(CacheName.user_info) != null)
					{
						list = (List<user_infoBO>)DataCache.GetCache(CacheName.user_info);
					}
					else
					{
			list = CBO.FillCollection<user_infoBO>(DataProvider.getInstance().getAll(TableName.user_info, PagingHelper.CreateOrder(new OrderObject(user_infoTable.user_id, SortOrder.Desc))));
						DataCache.SetCache(CacheName.user_info, list);
					}
				}
			}
			else
			{
					list = (List<user_infoBO>)DataCache.GetCache(CacheName.user_info);
			}
		return list;
		}
		public static int InsertUpdateDelete(user_infoBO user_info, ProviderAction action)
		{
			int rs = DataProvider.getInstance().InsertUpdateDelete(action, StoreProcedureName.InsertUpdateDelete_user_info, "@" + user_infoTable.user_id, user_info.user_id,user_info.firstname,user_info.lastname,user_info.department_code,user_info.branch_code, DataTools.ConvertType.ToInt(action));
			if (rs != -1)
			{
				DataCache.RemoveCache(CacheName.user_info);
			}
			return rs;
		}
        public static user_infoBO Login(string user, string pass)
        {
            ConnInfo.Db = "VNPT_Common";
            List<user_infoBO> lst = CBO.FillCollection<user_infoBO>(
                DataProvider.getInstance().ExecuteReader(StoreProcedureName.spGetUser, user, pass, null, null));
            if (lst.Count > 0)
                return lst[0];
            else
                return null;
        }
	}
}